<template>
    <div></div>
</template>
<script>
import { ScreenSpaceEventHandler, ScreenSpaceEventType, defined } from 'cesium';
import { getCultureInfoByTileFeature } from '@/request/request-api';
import { StaticHints } from '@/constant';

export default {
    name: 'ScenePicker',
    props: {
        innerRoomId: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            pickerInstance: null,
        }
    },
    mounted() {
        console.log('--------设置LEFT_CLICK--------');
        this.initCustScenePicker();
    },
    beforeDestroy() {
        // remove handler on LEFT_CLICK
        if (this.pickerInstance && this.pickerInstance !== null) {
            this.pickerInstance.removeInputAction(ScreenSpaceEventType.LEFT_CLICK);
        }
    },
    methods: {
        initCustScenePicker() {
            const viewer = window.viewer.viewerInstance;
            if (viewer && viewer !== null) {
                const handler = new ScreenSpaceEventHandler(viewer.canvas);
                handler.setInputAction(movement => {
                    const pickedFeature = viewer.scene.pick(movement.position);
                    if (defined(pickedFeature) && this.innerRoomId.length !== 0) {
                        const _content = pickedFeature._content;
                        getCultureInfoByTileFeature({
                            tileName: _content._tile._contentHeader.uri,
                            batchId: pickedFeature._batchId,
                            innerRoomId: this.innerRoomId
                        }).then(res => {
                            const result = res.data;
                            if (result.isExist) {
                                this.$parent.handleFeatureClick(result.cultureInfo);
                            } else {
                                this.$parent.issueNotification(StaticHints.PICK_WARNING_MSG, StaticHints.OPERATION_NOTIFICATION_TITLE, 'warning');
                            }
                        })
                    }
                }, ScreenSpaceEventType.LEFT_CLICK);
                this.pickerInstance = handler;
            }
        }
    }
}
</script>